package com.sa.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.sa.web.bean.AdminBean;
import com.sa.web.bean.UserBean;
import com.sa.web.dao.service.UserDao;

/**
 * 用户DAO
 */

public class UserDaoImpl implements UserDao {

	// 获取连接池
	private SqlMapClientTemplate sqlMapClientTemplate;

	/**
	 * 获得用户信息列表
	 */
	@Override
	public List<UserBean> getUserInfoList(String userName,int start, int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", start);
		map.put("size", size);
		return (List<UserBean>) sqlMapClientTemplate.queryForList("getUserList", map);
	}

	public List<String> queryUserInfo() {
		return sqlMapClientTemplate.queryForList("queryUserInfo");
	}
	
	/**
     * 添加用户信息
     */
	@Override
	public boolean addUserInfo(UserBean userBean) {
		return (Integer)sqlMapClientTemplate.insert("addUserInfo", userBean)>0;
	}
	
    /**
     * 删除用户信息
     */
	@Override
	public boolean deleteUserInfo(String userId) {
		return sqlMapClientTemplate.delete("deleteUserInfo",userId)>0;
	}
	/**
     * 更新用户信息
     */
	@Override
	public boolean updateUserInfo(UserBean userInfo) {
		return sqlMapClientTemplate.update("updateUserInfo", userInfo)>0;
	}

	/**
     * 获取单个用户信息
     */
	@Override
	public UserBean getUserInfo(String userId) {
		return (UserBean)sqlMapClientTemplate.queryForObject("getUserInfo", userId);
	}
	
	
	/**
	 * 获得用户信息总数
	 */
	@Override
	public Integer getUserInfoCount(String userName) {
		return (Integer) sqlMapClientTemplate.queryForObject("getUserInfoCount");
	}

	
	@Override
	public UserBean login(UserBean userBean) {
		return (UserBean)sqlMapClientTemplate.queryForObject("login", userBean);
	}

	@Override
	public void modifyUser(String username) {
		sqlMapClientTemplate.update("modifyUserFlag", username);
	}

	public SqlMapClientTemplate getSqlMapClientTemplate() {
		return sqlMapClientTemplate;
	}

	public void setSqlMapClientTemplate(
			SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}

}
